<?php
declare (strict_types = 1);

namespace app\validate;

use think\Validate;

class Member extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        // ID
        'id'        =>  'require',
        // 用户名
        'username'   =>  'require|max:11',
        // 密码
        'password'  =>  'require',
        // 能否登录
        'is_check'  =>  'require|number|between:0,1',
        // 性别
        'gender'    =>  'number|between:0,1',
        // 手机号
        'mobile'    =>  'max:11',
        // 权限
        'group_id'     =>  'require|number',
    ];
    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'id.require'        =>  'ID不能为空!',
        
        'username.require'  =>  '用户名不能为空!',
        'username.max'      =>  '用户名异常!',
        
        'password.require'  =>  '密码不能为空!',
        
        'is_check.require'  =>  '登录状态必填!',
        'is_check.number'   =>  '登录数值必须是数字类型!',
        'is_check.between'  =>  '登录数值超过范围!',
        
        'gender.number'     =>  '性别数值必须是数字类型!',
        'gender.between'    =>  '性别数值超出范围!',
        
        'mobile.max'        =>  '手机位数异常!',
        
        'group_id.require'     =>  '权限必选!',
        'group_id.number'      =>  '权限数值必须是数字类型!',
        
    ];
    
    /**
     * 定义验证场景
     * 格式：'场景名' =>  ['字段名','字段名'...]
     *
     * @var array
     */
    protected $scene = [
        'login'  =>  ['username','password'],
        'add'  =>  ['username','password','is_check'],
        'edit'  =>  ['id','username','is_check','group_id'],
        'change'  =>  ['id','username','is_check','group_id'],
        'delete'  =>  ['id'],
    ];   
}
